import request from '@/utils/request';
import type {
    UserResponse,
    Records,
    AllRolesData,
    AssignRoleData,
} from '@/api/acl/user/type';
enum API {
    // 获取用户列表
    GET_USER_LIST = '/admin/acl/user',
    // 新增用户
    ADD_USER = '/admin/acl/user/save',
    // 更新已有用户信息
    UPDATE_USER = '/admin/acl/user/update',
    // 获取全部职位以及当前账号拥有的
    GET_ALL_ROLE = '/admin/acl/user/toAssign',
    // 分配角色
    ASSIGN_ROLE = '/admin/acl/user/doAssignRole',
    // 删除某一用户
    DELETE_USER = '/admin/acl/user/remove',
    // 删除多个用户
    DELETE_MULTIPLE_USER = '/admin/acl/user/batchRemove',
}

// 获取用户列表
export const reqGetUserList = (page: number, limit: number, username: string) =>
    request.get<any, UserResponse>(
        API.GET_USER_LIST + `/${page}/${limit}/?username=${username}`,
    );

// 添加或者更新用户
export const reqAddOrUpdateUser = (data: Records) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATE_USER, data);
    } else {
        return request.post<any, any>(API.ADD_USER, data);
    }
};
// 获取全部职位以及当前账号拥有的
export const reqGetAllRole = (adminId: number) =>
    request.get<any, AllRolesData>(API.GET_ALL_ROLE + `/${adminId}`);
// 分配角色
export const reqAssignRole = (data: AssignRoleData) =>
    request.post<any, any>(API.ASSIGN_ROLE, data);
// 删除某一用户
export const reqDeleteUser = (id: number) =>
    request.delete<any, any>(API.DELETE_USER + `/${id}`);
// 删除多个用户

export const reqUserList = (idList: number[]) =>
    request.delete(API.DELETE_MULTIPLE_USER, { data: idList });
